package com.wc.AlgoOJ_train.train2_DP训练.c6.DP0303;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/1/13 15:31
 * @description 没有上司的舞会2
 * http://43.138.190.70:8888/p/DP0303
 */
public class Main {
    static int maxN = 500 + 7;
    static int[] happy = new int[maxN];
    // 存储
    // 用于存储每个节点的第一条边的编号
    static int[] h = new int[maxN];
    // 存储下一条边的编号
    static int[] ne = new int[maxN << 1];
    // 边
    static int[] e = new int[maxN << 1];
    static int tot = 0;

    static int n, m;
    // dp[i][j] 表示当前节点i选了j门课的最大happy度
    static int[][][] dp = new int[maxN][2][maxN];
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) {
        n = sc.nextInt();
        m = sc.nextInt();
        for (int i = 2; i <= n; i++) {
            int u = sc.nextInt();
            int v = i;
            add(u, v);
        }
        for (int i = 1; i <= n; i++) {
            happy[i] = sc.nextInt();
        }
        dfs(1);
        out.println(Math.max(dp[1][0][m], dp[1][1][m]));
        out.flush();
    }

    // a -> b
    static void add(int a, int b) {
        // 边连
        e[++tot] = b;
        // 前插法
        ne[tot] = h[a];
        h[a] = tot;
    }

    static void dfs(int u) {
        for (int i = 1; i <= m; i++) {
            dp[u][1][i] = happy[u];
        }
        for (int i = h[u]; i != 0; i = ne[i]) {
            int v = e[i];
            dfs(v);
            for (int j = m; j >= 1; j--) {
                for (int k = 1; k <= j; k++) {
                    dp[u][1][j] = Math.max(dp[u][1][j], dp[u][1][j - k] + dp[v][0][k]);
                    dp[u][0][j] = Math.max(dp[u][0][j], dp[u][0][j - k] + Math.max(dp[v][1][k], dp[v][0][k]));
                }
            }
        }
    }

}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }
}
